
$(".addListB p").click(async function (){
    let str = '';
    str = `
        <div class="parseInset" style="margin-top: 10px;width: 100%;display:table;position: relative">
            <div class="taskName col-sm-6" style="padding-left: 0">
              <input name="topicName" class="form-control" autocomplete="off" type="text" placeholder="请输入细则名称">
            </div>
            <div class="taskScore col-sm-6" style="padding-left: 0;padding-right: 0">
              <input name="score" class="form-control" autocomplete="off" type="text" placeholder="请输入分值">
            </div>
            <div class="taskDesc col-sm-12" style="padding-left: 0;padding-right: 0">
                <textarea name="description" class="form-control" autocomplete="off" type="text" placeholder="请输入具体细则"></textarea>
              </div>
            <div class="remove">删除</div>
        </div>     
    `;
    $("#addParams").append(str);

})

$(".addListB p").click()

$("body").on('click','.remove',function (){
    $(this).parents('.parseInset').remove();
})

$("#btn").click(function (){
    save();
})

function save() {

    let disposition = [] , maxScore = 0;

    $("#addParams").find(".parseInset").each(function (index,val){
        maxScore += parseFloat( $(val).find('.taskScore').find('input').val() );
        disposition.push({
            contentName: $(val).find('.taskName').find('input').val(),
            contentScore: $(val).find('.taskScore').find('input').val(),
            detailContent: $(val).find('.taskDesc').find('textarea').val(),
        })
    })

    let response = {
        createrId: sessionStorage.getItem('refereeId'),
        moduleName: $('#moduleName').val(),
        totalScore: maxScore,
        jzJinzhuanModuleContent:disposition
    }
    response = JSON.stringify(response);

    $.ajax({
        cache: true,
        type: "POST",
        url: "/jz-jinzhuan-module-content/insert",
        data: response,// 你的formid
        async: false,
        headers: {
            'Content-Type':'application/json;charset=UTF-8'
        },
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}